﻿using System;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Collections.Generic;
using ThapCam.System;
using ThapCam.Data.Collection;

namespace ThapCam.Ulti
{
    public class SessionManager
    {
        private ThapCamApplication application;

        public SessionManager(ThapCamApplication app)
        {
            application = app;
        }

        private HttpSessionState session
        {
            get
            {
                return application.Context == null ? null : application.Context.Session;
            }
        }

        public void addValue(string key, object value)
        {           
            try
            {
                session.Add(key, value);
            }
            catch (Exception ex)
            {
                LogManager.writeError(typeof(SessionManager).GetType(), null, ex);
            }
        }

        public void removeValue(string key)
        {
            try
            {
                if (session != null && session[key] != null)
                {
                    session[key] = null;
					session.Remove(key);
                }
            }
            catch (Exception ex)
            {
                LogManager.writeError(typeof(SessionManager).GetType(), null, ex);
            }
        }

        public object getValue(string key)
        {
            try
            {
                return session[key];
            }
            catch (Exception ex)
            {
                LogManager.writeError(typeof(SessionManager).GetType(), null, ex);
            }
            return null;
        }            
    }
}